package weaver.interfaces.avic;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * ͨ
 */
public class WeaTyyysqAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        int formid = requestInfo.getRequestManager().getFormid();
        formid = Math.abs(formid);
        String tablename = requestInfo.getRequestManager().getBillTableName();
        TySignFileUtil tyfileUtil = new TySignFileUtil();
        writeLog(">>>>WeaTyyysqAction>>>>requestid=" + requestid + ",tablename=" + tablename + ",formid=" + formid);
        try {
            rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            String yzmc = Util.null2String(rs.getString("yzmc"));
            String yyfs = Util.null2String(rs.getString("yyfs"));
            int sqr = Util.getIntValue(rs.getString("sqr"));
            String qswj = Util.null2String(rs.getString("qswj"));
            String fj = tyfileUtil.getImagefileIdByDocid(qswj);
            writeLog(">>>>WeaTyyysqAction>>>>yzmc=" + yzmc + ",sqr=" + sqr);
            writeLog(">>>>WeaTyyysqAction>>>>qswj=" + qswj + ",fj=" + fj);
            if ("0".equals(yyfs)) {
                int seccategory = 817;
                int docid = tyfileUtil.pdfFileSignSDK(fj + "", sqr, seccategory, mainid, tablename);
                writeLog(">>>>WeaTyyysqAction>>>>docid=" + docid);
                if (docid > 0) {
                    rs.executeUpdate("update " + tablename + " set gzhfj='" + docid + "' where requestid=?", requestid);
                    return Action.SUCCESS;
                } else {
                    requestInfo.getRequestManager().setMessageid("111111");
                    requestInfo.getRequestManager().setMessagecontent("xxxx");
                    return Action.FAILURE_AND_CONTINUE;
                }
            } else {
                return Action.SUCCESS;
            }

        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("xxxx");
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
